package com.jsoft.android.util;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ListPicker extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);

        setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, CHARACTERS));

        ListView lv = getListView();
        lv.setTextFilterEnabled(true);

        lv.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view,
              int position, long id) {
            // When clicked, show a toast with the TextView text
            /*Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
                Toast.LENGTH_SHORT).show();
              */
        	//Intent.setType("type..."); // http://developer.android.com/reference/android/content/Intent.html#setType(java.lang.String)
        	//Intent.setData("uri"); // http://developer.android.com/reference/android/content/Intent.html#setData(android.net.Uri)
        	  Bundle bundle = new Bundle();
        	  bundle.putCharSequence("APP_INVENTOR_RESULT", ((TextView) view).getText());
        	  Intent mIntent = new Intent();
              mIntent.putExtras(bundle);
              setResult(RESULT_OK, mIntent);
        	  //setResult(RESULT_OK);
            finish();
          }
        });
    }
    
    static final String[] CHARACTERS = new String[] {
        "red","green", "blue"
    };
}